<?php

namespace App\Models\Member;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class MemberLogin extends Model
{
    private static $returnData = array('code'=>0,'msg'=>'登录成功','data'=>[]);

    public static function LoginAction($fields)
    {
        $userBaseModel = new MemberBase();
        $member_id = $userBaseModel->validateMemberAccount($fields['user_name'],$fields['user_pass']);
        if(!$member_id){
            self::$returnData['code'] = 105;
            self::$returnData['msg'] = '账号或密码错误';
            return self::$returnData;
        }
        $userSessionModel = new MemberSession();
        $session_id = $userSessionModel->setSession(['member_id'=>$member_id]);
        if(!$session_id){
            self::$returnData['code'] = 99;
            self::$returnData['msg'] = '登录失败';
            return self::$returnData;
        }
        self::$returnData['data'] = array('token'=>$session_id);
        return self::$returnData;
    }
}
